package com.leetCode.problem;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-11-24 14:27:49
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-11-24     张李鑫                     1.0         1.0 Version
 */
public class Problem560 {
    /**
     * 给你一个整数数组 nums 和一个整数 k ，请你统计并返回该数组中和为 k 的连续子数组的个数。
     *
     * @param nums
     * @param k
     * @return
     */
    public static int subarraySum(int[] nums, int k) {
        return process(nums, 0, k);
    }

    /**
     * @param nums
     * @param i
     * @param k
     * @return
     */
    private static int process(int[] nums, int i, int k) {
        if (i == nums.length) {
            return k == 0 ? 1 : 0;
        }
//        if (k == 0) {
//            return 1 + process(nums, i + 1, k - nums[i]);
//        }
        int count = 0;
        for (int i1 = i; i1 < nums.length; i1++) {
            int process = process(nums, i1 + 1, k - nums[i]);
            int process1 = process(nums, i1 + 1, k);
            count += process;
            count += process1;
        }
        return count;
    }


}
